<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Method Modifiers</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="stackable.wait.html">Stackable::wait</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.mutex.html">Mutex</a></div>
 <div class="up"><a href="book.pthreads.html">pthreads</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="pthreads.modifiers" class="chapter">
 <h1>Method Modifiers</h1>

 
 <p class="para">
  pthreads overrides the functionality of the protected and private method modifiers in order to provide functionality more suited to multi-threaded objects.
  pthreads applies this functionality to all Thread, Worker and Stackable objects from creation.
 </p>
 <div class="example" id="example-3616">
  <p><strong>Example #1 protected method example: protected methods can only be executed by one Thread at a time.</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">ExampleThread&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Thread&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">run</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;thread&nbsp;code&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">synchronized</span><span style="color: #007700">())&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;function&nbsp;</span><span style="color: #0000BB">exclusive</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;synchronized&nbsp;method&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">$thread&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ExampleThread</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">$thread</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">start</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$thread</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exclusive</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>
 <div class="example" id="example-3617">
  <p><strong>Example #2 private method example: private methods may only be executed by the Thread, Worker, or Stackable during execution</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">ExampleThread&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Thread&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">run</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;thread&nbsp;code&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insideonly</span><span style="color: #007700">())&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;function&nbsp;</span><span style="color: #0000BB">insideonly</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;private&nbsp;method&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /><br /></span><span style="color: #0000BB">$thread&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ExampleThread</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">$thread</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">start</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$thread</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insideonly</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="stackable.wait.html">Stackable::wait</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.mutex.html">Mutex</a></div>
 <div class="up"><a href="book.pthreads.html">pthreads</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
